package aad.storyboard.view;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import aad.storyboard.controller.AudioPlayer;
import aad.storyboard.controller.StoryTimer;
import aad.storyboard.model.Layer;
import aad.storyboard.model.Scene;
import aad.storyboard.model.Script;
import aad.storyboard.model.Story;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.webkit.WebSettings;
import android.widget.TextView;

public class StaticScriptView extends TextView implements Observer{

	private Story story;
	private ArrayList <Script> scripts;
	private String subtitle;
	private double subtime=0;
	private double subend=0;
	private Integer inter=0;
	private int currentTime=0;
	
	public StaticScriptView(Context context, Story s) {
		
		super(context);
		story = s;
		Scene currentScene=story.getCurrentChapter().getCurrentScene();
		subtitle=currentScene.getScripts().get(0).getText();
		
	}

	
	public StaticScriptView(Context context, AttributeSet attrs)
    {
        super(context, attrs); 
        
        
    }
	
	@Override
	public void onDraw(Canvas canvas){		
		super.onDraw(canvas);		
		
		this.setText(subtitle+currentTime);
		invalidate();
	}


	@Override
	public void update(Observable timer, Object time) {
		currentTime=((StoryTimer)timer).getCurrentTime();
		inter=currentTime;		
		Scene currentScene = Story.getInstance().getCurrentChapter().getCurrentScene();
		
		for(int i=0; i<currentScene.getScripts().size(); i++){			
	          if(currentTime>=currentScene.getScripts().get(i).getStartTime()&&!currentScene.getScripts().get(i).isStarted()&&currentTime<=currentScene.getScripts().get(i).getEndTime()){	       	   
	        	  currentScene.setCurrentScript(currentScene.getScripts().get(i));
	        	  currentScene.getScripts().get(i).setStarted(true);
	        	  subtitle=currentScene.getScripts().get(i).getText();	        	 
	        	  subtime=currentScene.getScripts().get(i).getStartTime();
	        	  subend=currentScene.getScripts().get(i).getEndTime();	        	  
	        	  break;
	          }
	          
		 }
	}


}
